import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../controllers/home_controller.dart';

class HomeView extends GetView<HomeController> {

  List<BottomNavigationBarItem> buildBarItem() {
    List<BottomNavigationBarItem> list = [];
    controller.iconList.forEach((item) {
      list.add(BottomNavigationBarItem(
        icon: Image.asset(
          item['src'],
          fit: BoxFit.cover,
          width: 30,
          height: 30,
        ),
        activeIcon: Image.asset(
          item['src'],
          fit: BoxFit.cover,
          width: 30,
          height: 30,
          color: Colors.blue,
        ),
        label: item['title'],
      ));
    });
    return list;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Obx(
        () => IndexedStack(
          index: controller.currentIndex.value,
          children: controller.tabs,
        ),
      ),
      bottomNavigationBar: Obx(() => BottomNavigationBar(
            type: BottomNavigationBarType.fixed,
            selectedFontSize: 12,
            currentIndex: controller.currentIndex.value,
            items: buildBarItem(),
            onTap: (index) {
              controller.currentIndex.value = index;
            },
            fixedColor: Colors.blue,
            unselectedItemColor: Colors.grey,
            unselectedLabelStyle: TextStyle(),
          )),
    );
  }
}
